﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Organizer.ViewModel;

namespace Organizer
{
    public partial class TaskEditPage : PhoneApplicationPage
    {
        private TaskEditPageVM _viewModel;

        public TaskEditPageVM ViewModel
        {
            get { return _viewModel; }
        }


        public TaskEditPage()
        {
            InitializeComponent();                  
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            IDictionary<string, string> parameters = this.NavigationContext.QueryString;
            if (parameters.ContainsKey("TaskId"))
            {
                Guid idTask = Guid.Empty;
                if (Guid.TryParse(parameters["TaskId"], out idTask))
                {
                    //редакирование задачи                    
                    _viewModel = new TaskEditPageVM(idTask);     
                }
                else
                {
                    //создание задачи
                    _viewModel = new TaskEditPageVM(Guid.Empty);                                                     
                }
            }

            DataContext = _viewModel;
        }

        private void appBtnOk_Click(object sender, EventArgs e)
        {
            _viewModel.Save();
            NavigationService.Navigate(new Uri("/TaskList", UriKind.Relative));
        }

        private void appBtnCancel_Click(object sender, EventArgs e)
        {
            
        }

        private void textBoxTheme_GotFocus(object sender, RoutedEventArgs e)
        {
            ApplicationBar.IsVisible = false;
        }

        private void textBoxDescription_GotFocus(object sender, RoutedEventArgs e)
        {
            ApplicationBar.IsVisible = false;
        }

        private void textBoxTheme_LostFocus(object sender, RoutedEventArgs e)
        {
            ApplicationBar.IsVisible = true;
        }

        private void textBoxDescription_LostFocus(object sender, RoutedEventArgs e)
        {
            ApplicationBar.IsVisible = true;
        }
       
    }
}